#include <bits/stdc++.h>

#define in read()
#define fi first
#define se second
#define pb push_back
#define rep(i, x, y) for(int i = (x); i <= (y); i++)
#define per(i, x, y) for(int i = (x); i >= (y); i--)

using namespace std;

typedef long long ll;
typedef double db;
typedef vector < int > vec;
typedef pair < int , int > pii;

int read() {
    int x = 0; bool f = 0; char ch = getchar(); while(!isdigit(ch)) f |= ch == '-',ch = getchar();
    while(isdigit(ch)) x = x * 10 + (ch ^ 48),ch = getchar(); return f ? -x : x;
}

const int N = 3010;
const int inf = 0x3f3f3f3f;

int u[N], v[N], d[N], e[N], T, n, f[N][N];

inline void getmn(int &x, int y) { x = x < y ? x : y; }

int main() {
#ifndef ONLINE_JUDGE
    freopen("1.in","r",stdin);
#endif
    n = in, T = in; rep(i, 1, n) u[i] = in, v[i] = in, d[i] = in, e[i] = in;
	memset(f, 0x3f, sizeof f); f[0][0] = 0;
	rep(i, 1, n) {
		rep(j, 0, n - 1) getmn(f[i][j], f[i - 1][j + 1] + u[i] + e[i]);
		rep(j, 1, n) getmn(f[i][j], f[i - 1][j - 1] + v[i] + d[i]);
		rep(j, 1, n) getmn(f[i][j], f[i - 1][j] + e[i] + d[i]);
		rep(j, 0, n) getmn(f[i][j], f[i - 1][j] + u[i] + v[i]);
		rep(j, 1, n) getmn(f[i][j], f[i][j - 1] + d[i] + v[i]);
		per(j, n - 1, 0) getmn(f[i][j], f[i][j + 1] + u[i] + e[i]);
		rep(j, 0, n) if(f[i][j] < inf) f[i][j] += j * T * 2;
	}
	cout << f[n][0] + T * (n + 1) << endl; return 0;
}
